package com.flyqiu.form.api.store;

import com.flyqiu.common.dict.FlyQiuDicData;
import com.flyqiu.form.model.entity.FlyQiuTableConfig;

import java.util.List;

public interface FlyQiuFormStoreManage {

    /**
     * 注册存储服务
     *
     * @param storeService 存储服务
     */
    void registerStore(FlyQiuFormStoreService storeService);

    /**
     * 解除注册存储服务
     *
     * @param storeService 存储服务
     */

    void unregisterStore(FlyQiuFormStoreService storeService);

    /**
     * 获取存储服务
     *
     * @param flyQiuTableConfig 表单配置
     * @return {@link FlyQiuFormStoreService}
     */
    default FlyQiuFormStoreService getStoreService(FlyQiuTableConfig flyQiuTableConfig) {
        return getStoreService(flyQiuTableConfig.getDataStorageType());
    }

    /**
     * 获取存储服务
     *
     * @param flyQiuTableConfig 表单配置
     * @param throwException    获取失败时是否抛出异常
     * @return {@link FlyQiuFormStoreService}
     */
    default FlyQiuFormStoreService getStoreService(FlyQiuTableConfig flyQiuTableConfig, boolean throwException) {
        return getStoreService(flyQiuTableConfig.getDataStorageType(), throwException);
    }

    /**
     * 获取存储服务
     *
     * @param dataStorageType 存储类型
     * @return {@link FlyQiuFormStoreService}
     */
    default FlyQiuFormStoreService getStoreService(String dataStorageType) {
        return getStoreService(dataStorageType, true);
    }

    /**
     * 获取存储服务
     *
     * @param dataStorageType 数据存储类型
     * @param throwException  获取失败时是否抛出异常
     * @return {@link FlyQiuFormStoreService}
     */
    FlyQiuFormStoreService getStoreService(String dataStorageType, boolean throwException);


    /**
     * 获取存储字典
     *
     * @return {@link FlyQiuDicData}
     */
    List<FlyQiuDicData> getStoreDict();
}
